# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=recode

pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.6
pkgrel=3
pkgdesc="Converts files between various character sets and usages (mingw-w64)"
arch=('any')
url="http://recode.progiciels-bpi.ca/index.html"
license=('GPL' 'LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gettext")
options=('!strip' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/pinard/recode/tarball/v${pkgver}"
    01-no-usr-share-info-dir-gz
    02-src-libiconv-c-utf8
    03-src-task-c-librecode
    04-src-hash-h-php4-collision
    05-src-request-c-pointer-recalculation
    06-libtool-update
    07-po-update
    08-all-linguas-update
    09-manpage-name-section
    10-src-recodext-h-gcc-fix
    11-src-names-c-memory-leak
    12-src-names-c-format-string
    99-config-guess-config-sub
    'recode-3.6-as-if.patch'
    'recode-3.6-gettextfix.diff'
    'autotools.patch'
    'mingw.patch')
md5sums=('f82e9a6ede9119268c13493c9add2809'
         'ab75f350dc2f1828076a239b23cdc378'
         'b907cad925311f9251c49ecfd62feada'
         'bbda89d8d476ee87ecf2df3ae8830581'
         '1f91b5cd454ec2ec045b779d055d26a8'
         '9e5242946a3d129d40f2abb6abf836a1'
         '17d804d6e2916c34f4696e9e5ec20d40'
         '465a7f09fc77463dc9faf99c80ed94ad'
         'dacd18cf50eb46575396b502c50673ae'
         'c4603722c77031471d6f30c60587b324'
         '1366feefb8681765b218f2da85f8398d'
         '485c5af523524f5381db4b29fb79e42b'
         '6588da3ef236bb2748d3fb37df7a70fd'
         '9e15e2790c1728ae597432472e3392e2'
         'fca7484ba332c8ad59eb02334883cd92'
         'eb602e80a24b5448604bfebeacc55304'
         '8680ae965cdcd26f0dea1b8f85c34226'
         '515d43fe361a44f576fea310f85472ae')

prepare() {
  cd ${srcdir}/pinard-Recode-2127b34
  patch -Np1 -i ${srcdir}/recode-3.6-as-if.patch
  patch -Np1 -i ${srcdir}/recode-3.6-gettextfix.diff
  patch -Np1 -i ${srcdir}/01-no-usr-share-info-dir-gz
  patch -Np1 -i ${srcdir}/02-src-libiconv-c-utf8
  patch -Np1 -i ${srcdir}/03-src-task-c-librecode
  patch -Np1 -i ${srcdir}/04-src-hash-h-php4-collision
  patch -Np1 -i ${srcdir}/05-src-request-c-pointer-recalculation
  patch -Np1 -i ${srcdir}/06-libtool-update
  patch -Np1 -i ${srcdir}/07-po-update
  patch -Np1 -i ${srcdir}/08-all-linguas-update
  patch -Np1 -i ${srcdir}/09-manpage-name-section
  patch -Np1 -i ${srcdir}/10-src-recodext-h-gcc-fix
  patch -Np1 -i ${srcdir}/11-src-names-c-memory-leak
  patch -Np1 -i ${srcdir}/12-src-names-c-format-string
  patch -Np1 -i ${srcdir}/99-config-guess-config-sub
  patch -Np1 -i ${srcdir}/autotools.patch
  patch -Np1 -i ${srcdir}/mingw.patch
  sed -i '1i#include <stdlib.h>' src/argmatch.c
  sed -i -e '/^AM_C_PROTOTYPES/d' -e '/^AUTOMAKE_OPTIONS.*ansi2knr/d' \
  configure.in src/Makefile.am
  rm -f acinclude.m4
  autoreconf -fi
  libtoolize
}

build() {
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  export ac_cv_func_malloc_0_nonnull=yes
  export jm_cv_func_working_malloc=yes
  export jm_cv_func_working_realloc=yes
  ${srcdir}/pinard-Recode-2127b34/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --mandir=${MINGW_PREFIX}/share/man \
    --infodir=${MINGW_PREFIX}/share/info \
    --without-included-gettext
  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install

  rm "${pkgdir}${MINGW_PREFIX}"/lib/charset.alias
}
